#include "pir.h"
#include "rectype.h"
#include "util.h"
#include "nmfield.h"

using namespace std;
using namespace opsrc::stdf;

Pir::Pir()
{}


Pir::Pir(stdf_rec _stdfrec, int _reclen, std::ios::pos_type _fileRecFirstBytePosition, int _orderindex, endian e, char* buf)
    :RecBase(_stdfrec, _reclen, _fileRecFirstBytePosition, _orderindex),en(e) {
    if (buf != 0)
        readFields(buf);
}

Pir::~Pir() {
}

const StdfField<int> Pir::getHeadNum() const {
    return head_num;
}

void Pir::setHeadNum(StdfField<int> headnum) {
    head_num = headnum;
}

const StdfField<int> Pir::getSiteNum() const {
    return site_num;
}

void Pir::setSiteNum(StdfField<int> sitenum) {
    site_num = sitenum;
}


void Pir::readFields(char *buf) {

#if _DEBUG
    cout << "stdfrec= PIR , filebytestartposition= " <<   getFileRecByteStartPosition() << ", recbytecount= " << reclen <<endl;
#endif

    int curpos = 0;
    // Read head number , 1 byte
    NmField<unsigned int, 1> headnum(buf+curpos, en);
    head_num.set(headnum.getData(), curpos, headnum.getByteCount(), headnum.getTotalByteCount());
    curpos += head_num.getTotalByteCount();

    // Read site num, 1 byte
    if (curpos<reclen -1) {
 	NmField<unsigned int, 1> sitenum(buf+curpos, en);
    	site_num.set(sitenum.getData(), curpos, sitenum.getByteCount(), sitenum.getTotalByteCount());
	}
}
